package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsFluentFrameOutboundDetailsMapper;
import me.zhengjie.pojo.entity.WcsFluentFrameOutboundDetails;
import me.zhengjie.sqlservice.WcsFluentFrameOutboundDetailsService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class WcsFluentFrameOutboundDetailsServiceImpl extends ServiceImpl<WcsFluentFrameOutboundDetailsMapper, WcsFluentFrameOutboundDetails> implements WcsFluentFrameOutboundDetailsService {

    private final WcsFluentFrameOutboundDetailsMapper wcsFluentFrameOutboundDetailsMapper;

    @Override
    public boolean insertFluentFrameOutboundDetails(WcsFluentFrameOutboundDetails wcsFluentFrameOutboundDetails) {
        return wcsFluentFrameOutboundDetailsMapper.insert(wcsFluentFrameOutboundDetails) >0;
    }

    @Override
    public WcsFluentFrameOutboundDetails selectContainerCode(String containerCode) {
        LambdaQueryWrapper<WcsFluentFrameOutboundDetails> wcsFluentFrameOutboundDetailsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsFluentFrameOutboundDetailsLambdaQueryWrapper.eq(WcsFluentFrameOutboundDetails::getContainerCode,containerCode);
        return wcsFluentFrameOutboundDetailsMapper.selectOne(wcsFluentFrameOutboundDetailsLambdaQueryWrapper);
    }

    @Override
    public boolean deleteId(Integer idDetails) {
        return wcsFluentFrameOutboundDetailsMapper.deleteById(idDetails) >0;
    }

    @Override
    public boolean updateIsNest(Integer id, int isNest) {
        LambdaUpdateWrapper<WcsFluentFrameOutboundDetails> wcsFluentFrameOutboundDetailsLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsFluentFrameOutboundDetailsLambdaUpdateWrapper.set(WcsFluentFrameOutboundDetails::getIsNest,isNest)
                .set(WcsFluentFrameOutboundDetails::getUpdateTime, LocalDateTime.now())
                .eq(WcsFluentFrameOutboundDetails::getId,id);
        return wcsFluentFrameOutboundDetailsMapper.update(null,wcsFluentFrameOutboundDetailsLambdaUpdateWrapper)>0;
    }

    @Override
    public boolean updateAgvPlace(Integer id, int agvPlace) {
        LambdaUpdateWrapper<WcsFluentFrameOutboundDetails> wcsFluentFrameOutboundDetailsLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsFluentFrameOutboundDetailsLambdaUpdateWrapper.set(WcsFluentFrameOutboundDetails::getAgvPlace,agvPlace)
                .eq(WcsFluentFrameOutboundDetails::getId,id);
        return wcsFluentFrameOutboundDetailsMapper.update(null,wcsFluentFrameOutboundDetailsLambdaUpdateWrapper)>0;
    }

    @Override
    public boolean deleteContainerCode(String returnBox) {
        LambdaQueryWrapper<WcsFluentFrameOutboundDetails> wcsFluentFrameOutboundDetailsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsFluentFrameOutboundDetailsLambdaQueryWrapper.eq(WcsFluentFrameOutboundDetails::getContainerCode,returnBox);
        return wcsFluentFrameOutboundDetailsMapper.delete(wcsFluentFrameOutboundDetailsLambdaQueryWrapper)>0;
    }
}
